package vistas;

import java.awt.Color;
import java.awt.Graphics;

import objetos.aeronaves.Algo42;
import ar.uba.fi.algo3.titiritero.SuperficieDeDibujo;
import ar.uba.fi.algo3.titiritero.vista.Figura;

/*
 * Vista de la barra de energ�a del Algo42
 */
public class VistaBarraVida extends Figura {
	private static final long serialVersionUID = 6895069084519246352L;
	private int enX = 2;
	private int enY = 500;
	private int ancho;
	private int cantVida;
	private int maxVida;
	private Algo42 actor;

	public VistaBarraVida(Algo42 actor) {
		this.actor = actor;
		this.cantVida = actor.getCantidadEnergia();
		this.maxVida = actor.getCantidadEnergia();
		this.ancho = 10;
	}

	@Override
	public void dibujar(SuperficieDeDibujo superfice) {
		this.actualizar();
		Graphics graficoVida = (Graphics) superfice.getBuffer();
		Graphics graficoFondoVida = (Graphics) superfice.getBuffer();
		Graphics graficoTexto = (Graphics) superfice.getBuffer();
		graficoVida.setColor(this.getColor());
		graficoFondoVida.setColor(Color.black);
		int yDibujar = this.enY + this.maxVida - this.cantVida;
		graficoFondoVida.fill3DRect(this.enX, this.enY, this.ancho,
				this.maxVida, true);
		graficoVida.fill3DRect(this.enX, yDibujar, this.ancho, this.cantVida,
				true);
		graficoTexto.setColor(Color.red);
		graficoTexto.drawString(String.valueOf(this.cantVida), this.enX,
				this.enY + this.maxVida + 12);
	}

	@Override
	public Color getColor() {
		if (this.cantVida < this.maxVida / 3) {
			return Color.RED;
		} else if (this.cantVida < this.maxVida / 2) {
			return Color.YELLOW;
		}
		return Color.GREEN;
	}

	public void actualizar() {
		this.cantVida = this.actor.getCantidadEnergia();
	}

}
